<template>
  <!-- 登录写在这里 -->
  <!-- <img width="100%" src="../../assets/logo.png" alt=""> -->
  <div class="login_body">
    <div class="login_body_bgcolor">
      <h1 class="login_body_title">荔枝营销推广系统 ( AI智能客服版 )</h1>
    </div>
    <div class="login_body_main">
      <img class="logo_img" src="../../assets/logo.png" alt />
      <div class="login_body_main-control">
        <div>
          <label for="username">账号</label>
          <input id="username" type="text" placeholder="请输入手机号" v-model="phonenumber" />
        </div>
        <div>
          <label for="password">密码</label>
          <input id="password" type="password" placeholder="请输入密码" v-model="password" />
        </div>
        <span class="find_pass" @click="dialogFormVisible = true">忘记密码？</span>
        <div>
          <button @click="login">登 录</button>
          <button @click="$router.push({ name: 'Reg' })">注 册</button>
        </div>
      </div>
    </div>
    <el-dialog title="修改密码" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="输入邮箱" :label-width="formLabelWidth">
          <el-input v-model="form.email" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="输入密码" :label-width="formLabelWidth">
          <el-input v-model="form.password1" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="再次输入密码" :label-width="formLabelWidth">
          <el-input v-model="form.password2" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      phonenumber: null,
      password: null,
      dialogTableVisible: false,
      dialogFormVisible: false,
      form: {
        name: "",
        email: "",
        password1: "",
        password2: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: ""
      },
      formLabelWidth: "120px"
    };
  },
  methods: {
    login() {
      if (this.phonenumber == null || this.password == null) {
        this.$msgBox.show("请输入完整", "tip", 300, 60);
        return;
      }
      this.$axios
        .get("/api/login", {
          params: {
            phone: this.phonenumber,
            password: this.$md5.MD5_Encrypt(this.password)
          }
        })
        .then(({ data }) => {
          if (parseInt(data.code) === 200) {
            this.$msgBox.show("登录成功", "success", 250, 60);
            this.$cookie.setCookie("login", 1);
            this.$cookie.setCookie("name", data.data.nickName);
            this.$cookie.setCookie("expertBool", data.data.userType);
            this.$cookie.setCookie("phone", data.data.phone);
            this.$cookie.setCookie("id", data.data.id);
            this.$router.push({ name: "Home" });
          } else {
            this.$msgBox.show(data.msg, "error", 250, 60);
          }
        })
        .catch(error => {
          this.$msgBox.show("与服务器通信异常", "error", 250, 60);
        });
    }
  }
};
</script>

<style>
* {
  margin: 0px;
  padding: 0px;
}
.login_body {
  height: 100vh;
  width: 100vw;
}
.login_body_bgcolor {
  width: 100vw;
  background-color: #167a169a;
  height: 50vh;
}
.login_body_title {
  display: block;
  text-align: center;
  color: #fff;
  position: relative;
  top: 25%;
}
@media screen and (max-width: 500px) {
  .login_body_title {
    display: block;
    text-align: center;
    color: #fff;
    position: relative;
    top: 25%;
    font-size: 25px;
  }
}
.login_body_main {
  height: 250px;
  max-width: 500px;
  background-color: #fff;
  border: 1px solid #e0e0e0;
  margin: 0 auto;
  position: relative;
  top: -125px;
  border-radius: 5px;
}
/* .login_body_main img {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: #3d558a;
  margin: auto;
  position: absolute;
  left: 0;
  right: 0;
  top: -60px;
} */
.logo_img {
  width: 150px;
  height: 150px;
  margin: auto;
  position: absolute;
  left: 0;
  right: 0;
  top: -70px;
}
.login_body_main-control {
  border-top: 1px solid #e0e0e0;
  position: relative;
  top: 80px;
  height: calc(100% - 80px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.login_body_main-control > div {
  margin: 5px 0;
  display: flex;
}
.login_body_main-control > div label {
  margin-right: 5px;
  position: relative;
  top: 10px;
  font-size: 13px;
}
.login_body_main-control > div input {
  border: 1px solid #e0e0e0;
  outline-color: skyblue;
  border-radius: 5px;
  box-sizing: border-box;
  padding: 10px;
  width: 300px;
}
.login_body_main-control > div button {
  width: 80px;
  margin-right: 10px;
  /* flex:1; */
  color: #fff;
  background-color: #6284ff;
  border: 1px solid #6284ff;
  padding: 5px 10px;
  border-radius: 5px;
  font-weight: bold;
}
@media screen and (max-width: 500px) {
  .login_body_main {
    margin: 10px !important;
    padding: 10px;
    box-sizing: border-box;
  }
  .login_body_main-control > div label {
    display: none;
  }
}
.login_bttom {
  margin: -80px auto;
  width: 200px;
  height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.login_bttom > img {
  margin: 0 auto;
  width: 80%;
  height: 80%;
  justify-content: center;
}
.login_bttom > h3 {
  margin: 0 auto;
  font-size: 20px;
  line-height: 30px;
  justify-content: center;
}
@media screen and (max-width: 500px) {
  .login_bttom {
    margin: -140px auto;
    width: 200px;
    height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
}

.find_pass{
  cursor: pointer;
}
</style>